import axios from 'axios'

import { message } from 'antd'
// import { Alert, Button, Space } from 'antd';

const newAxios=axios.create({
    baseURL:'/api',
    timeout:3000,

 

    timeout:3000,
})

newAxios.interceptors.request.use(res=>{
    let token=localStorage.token
    if(token){
        res.headers.Authorization=token
    }
    return res
})

newAxios.interceptors.response.use(resp=>{
    return resp
},(error)=>{
    const response=error.response
    console.log(response);
    switch(response){
        case 401:
            message.error('登录过期，请重新登录')
            localStorage.clear()
            window.location.assign('#/login')
            break;
        case 404:
            message.error('服务器开小差！！！！')
    }
})

export default newAxios